home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_02_06
/
2n06050a
< prev
next >
Wrap
Text File
|
1991-04-30
|
23KB
|
902 lines
/**********************************************************
PURPOSE: Links with a Standard C program to
provide a Windows Application envirnment.
FUNCTIONS:
WinMain() - calls initialization function,
processes message loop
StdWinInit() - initializes window data and
registers window
StdWinWndProc() - processes messages
About() - processes messages for "About" dialog box
SelectFont() - select a font
GetSizes() - get size of current font
GetFonts() - get available fonts
SetMyDC() - initializes DC
COMMENTS: This code started as the Showfont sample
software that is included in the Windows Software
Development Kit. Compile this file as a small or
medium model with the following options:
CL /A[S or M] /c /Gsw /Oas /Zp -Zi STDWIN.C
The Zi option is only if you are able to use
CodeView for Windows.
When you link, you must link with the C6.0 linker
(Version 5.1 or greater), or link4 to get the proper
exe. You must link with the libraries that come with
the Windows Software Development kit, not the C
compiler libraries. These libraries are:
LIBW.LIB and SLIBCEW.LIB or MLIBCEW.LIB
After linking you must resource compile the
executable with the resource script. First:
rc -r stdwin.rc
After linking combine the binary resource file
with the exe by:
rc stdwin.res
***********************************************************/
#include "windows.h"
#include "StdWin.h"
#include <string.h>
#include <stdio.h>
/* set this to your own title */
char WindowTitle[] = "Grep";
WORD LineExtents[MAXROWS+2];
HANDLE hInst,hStdWinWnd;
HDC SetMyDC(HDC) ;
HFONT hFont1;
HFONT hUnderlineFont = 0,hBoldFont = 0,hItalicFont;
char FontNameList[32][128]; /* list of added fonts */
int nFontIndex = 0; /* position in FontList */
int BreakSet; /* break key flag */
BYTE KeyBuffer[64],KeyHead = 0,KeyTail = 0,KeyMask = 0x3f;
/* storage for screen text */
SCREEN ScreenBuffer[MAXROWS+2][MAXCOLUMNS];
int VisibleRows,VisibleCols,TopRow,LeftCol,VertScrollInc,
HorizScrollInc;
TEXTMETRIC TextMetric;
int AveCharacterWidth;
LOGFONT LogFont;
short nBkMode = OPAQUE;
DWORD rgbBkColor = RGB(255, 255, 255);
DWORD rgbTextColor = RGB(0, 0, 0);
DWORD rgbColor;
short nAlignLCR = TA_LEFT;
short nAlignTBB = TA_TOP;
char FontList[MAXFONT][32];
BYTE CharSet[MAXFONT];
BYTE PitchAndFamily[MAXFONT];
int FontIndex = 0;
int SizeList[MAXSIZE];
int SizeIndex = 0;
int CurrentFont = 0;
int CurrentSize = 0;
int xCurrentPos=0,yCurrentPos =0;
FARPROC lpColors;
FARPROC lpSelectFont;
FARPROC lpEnumFunc;
CATCHBUF CatchBuf;
short DisplayCol = 0,DisplayLine = 0;
RECT Rect; /* dimension of the client window */
BYTE *ptr,*ptr2;
/*********************************************************
FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
PURPOSE: calls initialization function,
processes message loop
***********************************************************/
int PASCAL WinMain(hInstance, hPrevInstance,
lpCmdLine, nCmdShow)
HANDLE hInstance;
HANDLE hPrevInstance;
LPSTR lpCmdLine;
int nCmdShow;
{
HWND hWnd;
MSG msg;
if (!hPrevInstance)
if (!StdWinInit(hInstance))
return (FALSE);
hInst = hInstance;
hWnd = CreateWindow("StdWin",
WindowTitle,
WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd)
return (FALSE);
hStdWinWnd = hWnd;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while(PeekMessage(&msg,NULL,0,0xFFFF,PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
/* store process state for ctrl-c break */
if(!Catch(CatchBuf))
main();
MessageBox(hWnd,"Program Terminated Normally",
WindowTitle,MB_OK);
if(hOutFile)
_lclose(hOutFile);
hOutFile = Redirected = 0;
while (GetMessage(&msg, NULL, NULL, NULL)) {
TranslateMessage(&msg);
DispatchMessage(&msg);}
return (msg.wParam);
}
/*********************************************************
FUNCTION: StdWinInit(HANDLE)
PURPOSE: Initializes window data and registers class
***********************************************************/
int StdWinInit(hInstance)
HANDLE hInstance;
{
HANDLE hMemory;
PWNDCLASS pWndClass;
BOOL bSuccess;
hMemory = LocalAlloc(LPTR, sizeof(WNDCLASS));
pWndClass = (PWNDCLASS) LocalLock(hMemory);
pWndClass->hCursor = LoadCursor(NULL, IDC_ARROW);
pWndClass->hIcon = LoadIcon(NULL, IDI_APPLICATION);
pWndClass->lpszMenuName = (LPSTR) "StdWin";
pWndClass->lpszClassName = (LPSTR) "StdWin";
pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH);
pWndClass->hInstance = hInstance;
pWndClass->style = NULL;
pWndClass->lpfnWndProc = StdWinWndProc;
bSuccess = RegisterClass((LPWNDCLASS) pWndClass);
LocalUnlock(hMemory);
LocalFree(hMemory);
return (bSuccess);
}
/**********************************************************
FUNCTION: SetMyDC(HDC)
PURPOSE: Initializes the DC
***********************************************************/
HDC SetMyDC(hDC)
HDC hDC;
{
SetBkMode(hDC, nBkMode);
SetBkColor(hDC, rgbBkColor);
SetTextColor(hDC, rgbTextColor);
SetTextAlign(hDC, nAlignLCR | nAlignTBB);
SelectObject(hDC,hFont1);
GetTextMetrics(hDC,&TextMetric);
}
/**********************************************************
FUNCTION: Colors(HWND, unsigned, WORD LONG)
PURPOSE: Dialog box for changing text background color
***********************************************************/
BOOL FAR PASCAL Colors(hDlg, message, wParam, lParam)
HWND hDlg;
unsigned message;
WORD wParam;
LONG lParam;
{
int Red, Green, Blue;
switch (message) {
case WM_INITDIALOG:
SetDlgItemInt(hDlg, ID_RED,
GetRValue(rgbColor), FALSE);
SetDlgItemInt(hDlg, ID_GREEN,
GetGValue(rgbColor), FALSE);
SetDlgItemInt(hDlg, ID_BLUE,
GetBValue(rgbColor), FALSE);
return (TRUE);
break;
case WM_COMMAND:
switch (wParam) {
case IDOK:
Red = GetDlgItemInt(hDlg, ID_RED,
NULL, FALSE);
Green = GetDlgItemInt(hDlg, ID_GREEN,
NULL, FALSE);
Blue = GetDlgItemInt(hDlg, ID_BLUE,
NULL, FALSE);
rgbColor = RGB(Red, Green, Blue);
EndDialog(hDlg, 1);
break;
case IDCANCEL:
EndDialog(hDlg, 0);
break;
}
break;
}
return (FALSE);
}
/********************************************************
FUNCTION: EnumFunc(LPLOGFONT,LPTEXTMETRIC,short,LPSTR)
**********************************************************/
int FAR PASCAL EnumFunc(lpLogFont, lpTextMetric,
FontType, lpData)
LPLOGFONT lpLogFont;
LPTEXTMETRIC lpTextMetric;
short FontType;
LPSTR lpData;
{
switch (LOWORD(lpData)) {
case 0:
if (FontIndex >= MAXFONT)
return (0);
_fstrcpy((LPSTR) FontList[FontIndex],
(LPSTR) (lpLogFont->lfFaceName));
CharSet[FontIndex] = lpLogFont->lfCharSet;
PitchAndFamily[FontIndex] =
lpLogFont->lfPitchAndFamily;
return (++FontIndex);
case 1:
if (SizeIndex >= MAXSIZE)
return (0);
SizeList[SizeIndex] = lpLogFont->lfHeight;
return (++SizeIndex);
}
}
/*******************************************************
FUNCTION: GetFonts(HWND)
PURPOSE: Get available fonts
*********************************************************/
void GetFonts(hWnd)
HWND hWnd;
{
HDC hDC;
FontIndex = 0;
SizeIndex = 0;
hDC = GetDC(hWnd);
lpEnumFunc = MakeProcInstance(EnumFunc, hInst);
EnumFonts(hDC, (LPSTR) NULL, lpEnumFunc, (LPSTR) NULL);
FreePr